home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / processes / pthreadsorts / sortablepicture.h < prev   
Encoding:
C/C++ Source or Header  |  2000-10-06  |  3.5 KB  |  103 lines

  1. /*
  2.     File:        SortablePicture.h
  3.  
  4.     Contains:    Header file for the Sortable Picture abstract base class.  This class is used as
  5.                         a base for all sorting classes that sort pictures.  Sorts that derive off this
  6.                         class are only required to overide the Sort method to allow sorting of a picture.
  7.                         the sort method should use the InOrder() method for comparing pixels and the
  8.                         SwapPixels() method to swap two pixels, this also allows the base class to keep track
  9.                         of Comparison and Swap counts.
  10.  
  11.     Written by:     Karl Groethe
  12.  
  13.     Copyright:    Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
  14.  
  15.             You may incorporate this Apple sample source code into your program(s) without
  16.             restriction. This Apple sample source code has been provided "AS IS" and the
  17.             responsibility for its operation is yours. You are not permitted to redistribute
  18.             this Apple sample source code as "Apple sample source code" after having made
  19.             changes. If you're going to re-distribute the source, we require that you make
  20.             it clear in the source that the code was descended from Apple sample source
  21.             code, but that you've made changes.
  22.  
  23.     Change History (most recent first):
  24.                         7/00    Created
  25. */
  26. #ifndef SORTABLE_PICTURE_H
  27. #define SORTABLE_PICTURE_H
  28. #include<Carbon/Carbon.h>
  29. #include<pthread.h>
  30.  
  31. #define kAppCreator '????'
  32.  
  33. //define to allow control over frame rate using '[' ']' and swap rate using '-' '+'
  34. #define SPEED_CONTROL
  35.  
  36. class SortablePicture
  37. {
  38. public:
  39.     enum{Class_ID='Spic'};
  40.     SortablePicture(ResID inPictID);
  41.     virtual CFStringRef GetSortName(){return CFSTR("");}
  42.     virtual ~SortablePicture();
  43.     virtual void CreatePictWindow();
  44.     virtual void DisposePictWindow();
  45.     virtual void AllocPictGWorld();
  46.     virtual void DisposePictGWorld();
  47.     virtual void AllocPixelArrays();
  48.     virtual void DisposePixelArrays();
  49.     virtual void Scramble();
  50.     virtual void Sort(){};
  51.     void SwapBytes(Byte* a, Byte* b,UInt32 numBytes);
  52.     virtual void SwapPixels(UInt32 indexA, UInt32 indexB);
  53.     virtual Boolean InOrder(UInt32 indexA, UInt32 indexB);
  54.     virtual void Draw();
  55.     virtual void UpdateStats();
  56.     Boolean GetShowStats();
  57.     void SetShowStats(Boolean show);
  58.     static void    DisposePictureWindow(WindowRef window);
  59.     static void* DrawThread(void* inPict);
  60.     static void* ScrambleAndSortThread(void* inPict);
  61.     static pascal OSStatus myWindowCloseHandler(EventHandlerCallRef inRef,
  62.                                                             EventRef inEvent,
  63.                                                             void* userData);
  64.     timespec GetFrameWaitTime();
  65.     
  66.     #ifdef SPEED_CONTROL
  67.     void SetFrameWaitTime(long eWait);
  68.     timespec GetSwapWaitTime();
  69.     void SetSwapWaitTime(long eWait);
  70.     #endif
  71. protected:
  72.     pthread_t scrambleAndSortThread;
  73.     pthread_t drawThread;
  74.     pthread_cond_t refresh;
  75.     pthread_mutex_t mutex;
  76.     
  77.     ResID pictID;
  78.     WindowRef pictWindow;
  79.     GWorldPtr pictGWorld;
  80.     Ptr          pictBaseAddr;
  81.     Rect      pictBounds;
  82.     UInt32* pixelIndexArray;
  83.     UInt32* pixelOffsetArray;
  84.     UInt32 bytesPerPixel;
  85.     UInt32 bytesPerRow;
  86.     UInt32 pictWidth;
  87.     UInt32 pictHeight;
  88.     UInt32 linearPictSize;
  89.     UInt32 swaps;
  90.     UInt32 comparisons;
  91.     
  92.     timeval frameTime;
  93.     UInt32 lastSwapVal;
  94.  
  95. private:
  96.     Boolean ShowStats;
  97.     timespec FrameWaitTime;
  98.     #ifdef SPEED_CONTROL
  99.     timespec SwapWaitTime;
  100.     #endif
  101. };
  102. #endif
  103.